<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function doCookie(){
            // 向cookie中写入数据
            // document.cookie = "name=tom"

            // var d = new Date()
            // d.setDate(d.getDate()+7) // 7天后过期
            // document.cookie = "age=18; expires=" + d.toGMTString()

            // 获取cookie数据
            var data = document.cookie
            console.log(data)
        }

        function doWebStorage(){
            // 向localStorage中写入数据
            // localStorage.setItem('address', '江苏')

            // 获取localStorage数据
            // console.log(localStorage.getItem('address'))

            // 删除数据
            // localStorage.removeItem('address')


            var user = {
                "name": "张三",
                "age": 21,
                "sex": "男",
                "height": 190.4
            }

            localStorage.setItem("user", JSON.stringify(user))

            var obj = JSON.parse(localStorage.getItem("user"))
            console.log(obj)
        }
    </script>
</head>
<body>
    <button onclick="doCookie()">操作Cookie</button>
    <button onclick="doWebStorage()">操作WebStorage</button>
</body>
</html>